package com.jdk.demo.fileChannel.read;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class Test2_2 {

	// 验证read方法是从通道的当前位置开始读取
	public static void main(String[] args) throws Exception {
		FileInputStream fisRef = new FileInputStream("b.txt");
		FileChannel fileChannel = fisRef.getChannel();
		
		fileChannel.position(2);
		ByteBuffer bytebuffer = ByteBuffer.allocate(5);
		fileChannel.read(bytebuffer);
		
		byte[] getByteArray = bytebuffer.array();
		for (int i = 0; i < getByteArray.length; i++) {
			System.out.print((char)getByteArray[i]);
		}
		fileChannel.close();
		fisRef.close();
	}
	
}
